package com.ttn.auth.controller;

import com.ttn.auth.service.SysRoleService;
import com.ttn.common.core.entity.Result;
import com.ttn.common.core.entity.auth.SysRole;
import com.ttn.common.core.entity.auth.query.SysRolePageQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (sys_role)表控制层
 *
 * @author xxxxx
 */
@RestController
@Slf4j
@RequestMapping("/sys-role")
public class SysRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    /**
     * 增加角色权限
     *
     * @param request
     * @param sysRole
     * @return
     */
    @PostMapping("/save/sys-role")
    public Result saveSysRole(HttpServletRequest request, @RequestBody SysRole sysRole) {
        log.info("SysRoleController saveSysRole ,参数:{}", sysRole);
        sysRoleService.save(sysRole);
        return Result.success();
    }

    /**
     * 修改用户权限
     *
     * @param request
     * @param sysRole
     * @return
     */
    @PutMapping("/modify/sys-role")
    public Result modifySysRole(HttpServletRequest request, @RequestBody SysRole sysRole) {
        log.info("SysRoleController saveSysRole ,参数:{}", sysRole);
        sysRoleService.updateById(sysRole);
        return Result.success();
    }

    /**
     * 获取角色列表
     *
     * @param request
     * @param sysRolePageQuery
     * @return
     */
    @PostMapping("/query/sys-role-page")
    public Result querySysRolePage(HttpServletRequest request, @RequestBody SysRolePageQuery sysRolePageQuery) {
        log.info("SysRoleController querySysRolePage ,参数:{}", sysRolePageQuery);
        return sysRoleService.querySysRolePage(sysRolePageQuery);
    }

    /**
     * 通过id查询角色详情
     *
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/query/sys-role-by-id/{id}")
    public Result querySysRoleById(HttpServletRequest request, @PathVariable("id") Integer id) {
        log.info("SysRoleController querySysRoleById ,参数:{}", id);
        return sysRoleService.querySysRoleById(id);
    }

    /**
     * 删除系统用户
     *
     * @param request
     * @param id
     * @return
     */
    @DeleteMapping("/delete/sys-role-by-id/{id}")
    public Result deleteSysRoleById(HttpServletRequest request, @PathVariable("id") Integer id) {
        log.info("SysRoleController deleteSysRoleById ,参数:{}", id);
        sysRoleService.removeById(id);
        return Result.success();
    }

}
